package day23;

import java.io.*;

public class Homework1 {
    public static void main(String[] args) {
        File file=new File("C:\\Users\\梅穿内裤\\Desktop\\HelloWorld.txt");
        File newFile=new File("C:\\Users\\梅穿内裤\\Desktop\\IOTest\\HelloWorld.txt");
        if (file.isFile()){
            FileInputStream fis=null;
            FileOutputStream fos=null;
            try {
                fis=new FileInputStream(file);
                fos=new FileOutputStream(newFile);
                byte bs[]=new byte[1024];
                int len=0;
                while ((len=fis.read(bs))!=-1){
                    fos.write(bs,0,len);
                }
                System.out.println("复制成功");
                System.out.println("目录下的文件有:");
                File file1=newFile.getParentFile();
                String name[]= file1.list();
                for (String names:name){
                    System.out.println(names);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    fis.close();
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }else {
            System.out.println("该文件是目录！");
        }
    }
}
